package org.rohmh.generic.entity;
import java.util.UUID;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.PrePersist;

/**
 *
 * @author Daniel Walker <plaxdan@gmail.com>
 */
@MappedSuperclass
public abstract class UUIDEntity<E extends UUIDEntity<?>>  extends AbstractEntity<E, UUID> {

    private UUID id;

    protected UUIDEntity() {
        // Required by JPA
    }

    @Id
    @Override
    public UUID getUUID() {
        return id;
    }

    @Override
    public void setUUID(UUID uuid) {
        this.id = uuid;
    }

    @PrePersist
    protected void initializeId() {
        setUUID(UUID.randomUUID());
    }
}

